using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using AvaloniaInfiniteScrolling;

namespace AvaloniaInfiniteScrollingApp;

public partial class MainWindow : Window {
    private int _pageIndex = 0;
    private const int _pageSize = 10;
    private const int _maxPageIndex = 10;

    public MainWindow() {
        InitializeComponent();
        aisc.ItemsSource = new AvaloniaInfiniteScrollCollection<string> {
            OnCanLoadMore = () => _pageIndex < _maxPageIndex,
            OnLoadMore = async () => {
                await Task.Delay(1000);
                var items = Enumerable.Range(_pageIndex * _pageSize, _pageSize).Select(p => $"Item {p}")
                    .ToList();
                _pageIndex++;
                return items;
            }
        };
    }
}